////关闭窗口
function closeWindow(){
		window.opener = null;
		window.open("","_parent","");
		window.close();
}


/***编辑框**/
var contentEditor;
KindEditor.ready(function(K) {
	contentEditor = K.create('#fcontent', {
		width:'98%',
		height:'650px',
		allowPreviewEmoticons : false,
		allowImageUpload : false,
		resizeType:0,
		htmlTags:{
			font : ['color', 'size', 'face'],
//	        span : [
//	                '.color', '.background-color', '.font-size', '.font-family', '.background',
//	                '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
//	        ],
//	        div : [
//	                'align', '.border', '.margin', '.padding', '.text-align', '.color',
//	                '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
//	                '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
//	        ],
	        table: [
	                'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
	                '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
	                '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
	                '.width', '.height', '.border-collapse'
	        ],
	        'td,th': [
	                'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
	                '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
	                '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
	        ],
	        a : ['href', 'target', 'name'],
	        embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
	        img : ['src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
	        'p,span,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
	                'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
	                '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left','.line-height'
	        ],
	        pre : ['class'],
	        hr : ['class', '.page-break-after','custompaging'],
	        'tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : [],
	        '　':[],
	        br:[],
	        marquee:['direction','height']
		},
		items : [
			'source','undo', 'redo', '|', 'preview',  'template',  'cut', 'copy', 'paste',
			'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
			'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
			'superscript', 'clearhtml', 'quickformat', 'selectall', '|',  '/',
			'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
			'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 
			 'table','imgupload','paging','fullscreen']
	});
//	fSummaryEditer = K.create('#fSummary',{
//		width:'98%',
//		height:'80px',
//		resizeType : 0,
//		allowPreviewEmoticons : false,
//		allowImageUpload : false,
//		htmlTags:{
//			font : ['color', 'size', 'face'],
//	        span : [
//	                '.color', '.background-color', '.font-size', '.font-family', '.background',
//	                '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
//	        ],
//	        div : [
//	                'align', '.border', '.margin', '.padding', '.text-align', '.color',
//	                '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
//	                '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
//	        ],
//	        table: [
//	                'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
//	                '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
//	                '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
//	                '.width', '.height', '.border-collapse'
//	        ],
//	        'td,th': [
//	                'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
//	                '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
//	                '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
//	        ],
//	        a : ['href', 'target', 'name'],
//	        embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
//	        img : ['src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
//	        'ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
//	                'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
//	                '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
//	        ],
//	        pre : ['class'],
//	        hr : ['class', '.page-break-after'],
//	        'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : []
//		},
//		items : [
//					 'fontname', 'fontsize', '|',
//					 'forecolor', 'hilitecolor', 'bold',
//					'italic', 'underline', 'strikethrough',  'removeformat', '|', 
//					'undo', 'redo', '|',
//					'plainpaste',  '|', 'justifyleft', 'justifycenter', 'justifyright', 'preview'
//					]
//	});
	var colorpicker;
	K('#colorpicker').bind('click', function(e) {
		e.stopPropagation();
		if (colorpicker) {
			colorpicker.remove();
			colorpicker = null;
			return;
		}
		var colorpickerPos = K('#colorpicker').pos();
		colorpicker = K.colorpicker({
			x : colorpickerPos.x,
			y : colorpickerPos.y + K('#colorpicker').height(),
			z : 19811214,
			selectedColor : 'default',
			noColor : '无颜色',
			click : function(color) {
				$("#text_color").val('');
				$("#text_color").val(color);
				$("#ftitle").css("color",color);
				colorpicker.remove();
				colorpicker = null;
			}
		});

	});
	K(document).click(function() {
		if (colorpicker) {
			colorpicker.remove();
			colorpicker = null;
		}
	});

});

var EditArticle = {};
var DivTab = {
	clickOn:function(id,di){
		$("#div_tab"+id).removeClass();
		$("#div_tab"+id).addClass('div_li_style_on');
		$("#div_tab_sorce"+id).show();
		$("#div_tab"+di).removeClass();
		$("#div_tab"+di).addClass('div_li_style');
		$("#div_tab_sorce"+di).hide();
	}	
};
//加载数据
EditArticle.loadSource = function(){
	$.ajax({
		url:'addArticleSource',
		type:'post',
		dataType:'json',
		success:function(data){
			var classHtml = '',typeHtml = '';
			
			$.each(data.articleClass,function(i,u){
				if($("#update_fclassid") != undefined){
					if($("#update_fclassid").val() == u.id){
						classHtml += '<option value="'+u.id+'" selected="selected">'+u.fclassname+'</option>';
					}else{
						classHtml += '<option value="'+u.id+'">'+u.fclassname+'</option>';
					}
				}else{
					classHtml += '<option value="'+u.id+'">'+u.fclassname+'</option>';
				}
			});
			$.each(data.articleType,function(j,k){
				if($("#update_ftypeid") != undefined){
					if($("#update_ftypeid").val() == k.id){
						typeHtml += '<option value="'+k.id+'" selected="selected">'+k.ftypename+'</option>';
						
						showHintText(k.ftypename);//show hint
						
						if(k.ftypename == '全屏视频' || k.ftypename == '视频'){
							$("#full_video").hide();
//							$("#play_type").show();
							$("#videobank").show();
						}
						if(k.ftypename == '图文+视频'){
							$("#videobank").show();
						}
						if(k.ftypename == '音频'){
							$("#full_video").show();
//							$("#play_type").show();
							$("#voicebank").show();
						}
						if(k.ftypename == '链接' || k.ftypename == '图片'){
							$("#kindediter_panner").hide();
							$("#_fcontent").show();
							$("#_fcontent").addClass('input_text');
							$("#_fcontent").after('<font id="tip_text" size="3" color="red">*输入有效的URL</font>');
							$("#bannerImg").show();
							
							$("#videobank").hide();
							$("#voicebank").hide();
							contentEditor.html('');
						}
					}else{
						typeHtml += '<option value="'+k.id+'">'+k.ftypename+'</option>';
					}
				}else{
					typeHtml += '<option value="'+k.id+'">'+k.ftypename+'</option>';
				}
			});
			$("#fclassid").html(classHtml);
			$("#ftypeid").html(typeHtml);
		},
		error:function(msg){
			$.growlUI('数据加载出错！');
		}
	});
};
/**
 * 图片数据
 * 视频数据
 */
//创建dialog
var 	sourcekdialog;
EditArticle.source = function(type,ft,target){	
	$("#start").val(0);
	$("#limit").val(9);
	$("#type").val(type);

	EditArticle.createDialog(ft,target);
	
	$("#source_form").ajaxSubmit({
		url:'resouceList',
		type:'post',
		dataType:'json',
		success:function(data){
			page(data.count,$("#limit").val(),1,"pagePanel","gotoPageSource",true,null,null,false);
			//加载添加时间
			var lines = '<option value="">全部</option>';
			$.each(data.addTime,function(j,m){
				if(m != null)
					lines += '<option value="'+m+'">'+m+'</option>';
			});
			$("#faddTimeQuery").html(lines);
			
			bindGridSource(data);
		},	
		error:function(msg){
			$.growlUI('数据加载出错！');
		}
	});
};
EditArticle.selectAddTimeQuery = function(type){
	$("#start").val(0);
	
	var datas = {'faddtime':$("#faddTimeQuery").val()==""?null:$("#faddTimeQuery").val(),'fname':$("#searchSourceName").val()==""?null:$("#searchSourceName").val()};
	
	$("#source_form").ajaxSubmit({
		url:'resouceList',
		type:'post',
		dataType:'json',
		data:datas,
		success:function(data){
			page(data.count,$("#limit").val(),1,"pagePanel","gotoPageSource",true,null,null,false);
			bindGridSource(data);
		},
		error:function(msg){
			$.growlUI('数据加载出错！');
		}
	});
};
//创建弹出层
EditArticle.createDialog = function(ftitle,target){
		sourcekdialog = KindEditor.dialog({
			width : 800,
			height: 600,
			title : ftitle,
			body : '<div><div id="time_source">添加时间：<select id="faddTimeQuery"  style="width:180px;font-size:13px;"></select>资源名称：<input type="text" id="searchSourceName" /><input type="button" value="    搜   索     " onclick="EditArticle.selectAddTimeQuery()"/></div><div id="source_div" style="padding:10px;"></div></div>',
			shadowMode:true,
			closeBtn : {
				name : '关闭',
				click : function(e) {
					sourcekdialog.remove();
				}
			},
			yesBtn : {
				name : '确定',
				click : function(e) {
					var resid = $("input[name='sourceId']:checked").val();
					if(resid != undefined){
						
						if(ftitle == '图片库'){
							var type = $("#ftypeid").find(":selected").text();
							if(type == "图片" && target == "ftitle"){
								$("#" + target).val($("#fresourceurl"+resid).attr("src"));
							}
							if(target == "edit"){
								contentEditor.insertHtml('<img  src="'+$("#fresourceurl"+resid).attr("src") + '" />');
							}
							if(type == "图文+视频" || target != "edit"){
								$("#"+target+"fresourceurl").val($("#fresourceurl"+resid).attr("src"));
								$("#img_"+target+"_id").val(resid);
								$("#img_"+target+"_show_min").show(100);
								$("#img_"+target+"_show").attr('src',$("#fresourceurl"+resid).attr("src"));
							}
							
						}else if(ftitle == '视频库'){
							$("#videofresourceurl").val($("#fresourceurl"+resid).attr("src"));
							$("#videoImg").attr("src",$("#fresourceurl"+resid).attr("src"));
							$("#fresourceid").val(resid);
						}else if(ftitle == '音频库'){
							$("#voicefresourceurl").val($("#fresourceurl"+resid).attr("src"));
							$("#voiceImg").attr("src",$("#fresourceurl"+resid).attr("src"));
							$("#fresourceid").val(resid);
						}
						sourcekdialog.remove();
					}	
				}
			},
			noBtn : {
				name : '取消',
				click : function(e) {
					sourcekdialog.remove();
				}
			}
		});
};


function gotoPageSource(start){
	$("#start").val(start);
	var datas = {'faddtime':$("#faddTimeQuery").val()==""?null:$("#faddTimeQuery").val(),'fname':$("#searchSourceName").val()==""?null:$("#searchSourceName").val()};
	
	$("#source_form").ajaxSubmit({
		url:'resouceList',
		type:'post',
		dataType:'json',
		data:datas,
		success:function(data){
			bindGridSource(data);
		},
		error:function(msg){
			$.growlUI('数据加载出错！');
		}
	});
}
function bindGridSource(data){
	$("#totalCount").html('总共：'+data.count+'条');
	var html = '<table  width="100%" border="0">';
	if(data.source != ''){
		var tem = 0;
		var wH,hH,zoom;
		$.each(data.source,function(i,u){
			zoom = Math.max( Math.max(u.fwidth/150,1) , Math.max(u.fheight/110,1) );
			wH   = u.fwidth / zoom;
			hH   = u.fheight / zoom;
			
			var line = '';
			if(tem == 0){
				line = '<tr style="height:130px;">';
			}
				line +='<td width="33%" style="text-align:center;"><img id="fresourceurl'+u.id+'" title="' + u.fname + '" src="'+u.fresourceurl+'" onclick="document.getElementById(\'sourceId'+u.id+'\').checked=true;"  onerror="this.src = \'/CMS/images/imgprew.png\'" style="width:' + (wH > 0?wH:100) + 'px;height:' + (hH > 0?hH:100) + 'px;cursor:pointer;"/>'
						+'<Br><span  style="font-size:13px;color:#688187;overflow: hidden;white-space: nowrap; text-overflow: ellipsis;display:inline-block;width:150px;">'+u.fname+'</span><Br>'
						+'<input type="radio" id="sourceId'+u.id+'" name="sourceId" value="'+u.id+'" /></td>';
				tem ++;	
				
			if(tem == 3){
				line += '</tr>';
				tem = 0;
			}	
			html += line;	
		});
		
	}else{
		html += '<tr><td colspan="3" style="text-align:center;">无数据</td></tr>';
	}
	html += '</table>';
	var htmlStr =  html + $("#source_div_foot").html();
//	$.growlUI(htmlStr);
	if($("#type").val() == 1){///图片加载器
		var imgtab = '<div style="width:100%;height:auto !important;min-height:30px;border:1px solid #ffffff;">'
			+'<div id="div_tab1" onclick="DivTab.clickOn(1,2)" class="div_li_style_on">图片库</div><div id="div_tab2" onclick="DivTab.clickOn(2,1)" class="div_li_style">上传图片</div>'
			+'<div id="div_tab_sorce1" style="width:100%;border:1px solid #ffffff;border-top-color:#ccc;margin-top:20px;">'+htmlStr+'</div>'
			+'<div id="div_tab_sorce2" style="width:100%;border:1px solid #ffffff;border-top-color:#ccc;margin-top:20px;display:none;">'
			+'<div style="margin-top:20px;"><form id="img_upload_form" action="article_uploadimage" method="post" enctype="multipart/form-data">'
			+'选择图片：<input type="file" name="file" style="font-size:13px;" onchange ="ImgUpload.validataFileType(this)"/>'
			+'<input type="button" value="上传" id="uploadimg" onclick="ImgUpload.imgupload()" style="font-size:13px;width:50px;"/>'
			+'(支持格式：.gif.jpg.jpeg.png)</form></div>'
			+'<div style="clear:both;"></div></div>'
			+'</div>';
		$("#source_div").html(imgtab);
	}else{
		$("#source_div").html(htmlStr);
	}
}
var ImgUpload ={
		//上传图片验证
		validataFileType:function(obj){
			var img = obj.value;
			var suffix =img.substring(img.lastIndexOf("."),img.length);
			var rep = new RegExp('(.gif|.GIF|.jpeg|.JPEG|.jpg|.JPG|.png|.PNG]$)');
			if(!rep.test(suffix)){
				$.growlUI('图片格式不正确');
				$("#uploadimg").attr('disabled','disabled');
			}else{
				$("#uploadimg").attr('disabled',false);
			}
		},
		//上传
		imgupload:function(){
			if($("input[type=file][name='file']").val() != ''){
				$("#img_upload_form").ajaxSubmit({
					url:'article_uploadimage',
					type:'post',
					dataType:'json',
					success:function(data){
						if(data > 0){
							$.growlUI('上传成功');
							sourcekdialog.remove();
							EditArticle.source(1,'图片库');
						}else{
							$.growlUI(data);
						}
					},
					error:function(msg){
						$.growlUI('上传出错');
					}
				});
			}else{
				$.growlUI('请选择图片');
			}
		}
		
};

//添加文章
EditArticle.addArticle = function(local,check){
	
	if(viladateForm()){
	
	_waiting._show('正在加载栏目,请稍后');		
	var webid = $("#websiteinfoId").val(),webtitle = $("#websiteinfotitle").val();
	var html = '';
	var divS = '<div id="tcol_dataGrid" style="padding:10px;height:400px;overflow:auto;overflow-x:hidden;">';
	var divE = '</div>';
	
	$.ajax({
		url:'websiteinfoSource',
		type:'post',
		dataType:'json',
		success:function(data){
				html += '选择网站:';
				html += '<select id="saveArticle_web" onchange="TcolunmSource(this,\''+local+'\')" style="width:150px;font-size:14px;color:#5E5E5E;margin-top:-3px;" ><option value="" disabled="disabled" selected="selected">----站点列表----</option>';
			$.each(data,function(i,u){
				if(webid != '' && webid != null){
					if(u.id == webid){
						html += '<option value="'+u.id+'" selected="selected">'+u.ftitle+'</option>';
					}else{
						html += '<option value="'+u.id+'">'+u.ftitle+'</option>';
					}
				}else{
					html += '<option value="'+u.id+'">'+u.ftitle+'</option>';
				}
			});
			html += '</select><input id="C_WEB_NAME" type="text" onkeyup="extendArticle.addDivPanel(this,\'TcolunmSource(this,null,true)\')" onblur="extendArticle.delDivPanel()"  style="margin-left:-150px;font-size:14px; position: relative;width:130px;"/>';
			
			if(webid != '' && webid != null){
				$.ajax({
					url:'tcolunmSource',
					type:'post',
					data:{'webid':webid,'check':'0','type':0},
					dataType:'json',
					success:function(data){
						html += divS;
						html +=	$.fn.simpleTree(data,local,true,webtitle);
						html += divE;
						EditArticle.columnList(html,check);
					},
					error:function(msg){
						$.growlUI('栏目加载出错');
					}
				});
				
			}else{
				html += divS + divE;
				EditArticle.columnList(html,check);
			}
		},
		error:function(msg){
			_waiting._hide();
			$.growlUI('网站数据加载出错');
		}
	});
	
	}
};
/*检查标题  模板是否选择*/
function  viladateForm(){
	var title = $("#ftitle").val().trim();
//	var tem = $("#ftemplatename").val().trim();
	var type = $("#ftypeid option:selected").text();
	
	if(title == ''){
		$("#ftitle").css("border","2px solid red");
	}else{
		$("#ftitle").css("border","2px #B3B3B3 solid");
	}
	
//	tem = (type == '视频' || type == '全屏视频' || type == '图文+视频' || type == '链接')?"11":tem;
//	
//	if(tem == ''){
//		$("#ftemplatename").css("border","2px solid red");
//	}else{
//		$("#ftemplatename").css("border","1px solid #ccc");
//	}
	return (title != '');
}

//网站栏目数据
function TcolunmSource(obj,local,isSelect){
	if(isSelect)
		$("#C_WEB_NAME").val(obj.innerHTML);
	else
		$("#C_WEB_NAME").val(obj.options[obj.selectedIndex].text);
	
	_waiting._show('正在加载栏目，请稍后');
	local = local != null?local:'/CMS';
	$.ajax({
		url:'tcolunmSource',
		type:'post',
		data:{'webid':isSelect == undefined?obj.value:obj.id,'check':'0','type':0},
		dataType:'json',
		success:function(data){
			_articleCount = 0 ;
			$("#tcol_dataGrid").html($.fn.simpleTree(data,local,true,isSelect == undefined?obj.options[obj.selectedIndex].text:obj.innerHTML,102));
			$("#website_ArticleCont102").html('('+_articleCount+')');
			_waiting._hide();
		},
		error:function(msg){
			_waiting._hide();
			$.growlUI('栏目加载出错');
		}
	});
}
EditArticle.columnList = function(html,check){
	var column = '';		
	var kdialog	= KindEditor.dialog({
					width : 800,
					height: 600,
					title : '栏目',
					body : '<div  style="padding:10px;">'+html+'</div>',
					shadowMode:true,
					closeBtn : {
						name : '关闭',
						click : function(e) {
							kdialog.remove();
						}
					},
					yesBtn : {
						name : '确定',
						click : function(e) {
							var ckSize = $("input[type='checkbox'][name='columnId']:checked").size();
							if(ckSize > 0){
								$("input[type='checkbox'][name='columnId']:checked").each(function(){
									column += ',' + $(this).val();
								});
//								$.growlUI(column);
								//添加文章信息
//								var ftitle = '';
//								if($("#text_color").val() != ''){
//									ftitle = '<span style="color:'+$("#text_color").val()+'" >' + $("#ftitle").val() + '</span>';
//								}else{
//									ftitle = $("#ftitle").val();
//								}
								if(contentEditor.html() != '')
									$("#_fcontent").val(contentEditor.html());
								
								var fchecked = 2;
								if(check == 2)
									fchecked = 0;
								
								var fsumm = '';
								if($("#ico_checkbox").attr("checked")){
									
									var ico_t = $("input[type='checkbox'][name='ico']:checked").size();
									if(ico_t > 0){
										$("input[type='checkbox'][name='ico']:checked").each(function(){
											if($(this).val() == '时间'){
												var date = new Date(),ds;
												if($("#fsummary_text").val() == ''){
													ds = "【" + date.getFullYear() + "-"+ (date.getMonth()+1) + "-" + date.getDate() + "】";
												}else{
													ds = $("#fsummary_text").val();
												}
												fsumm += ds;
											}else{
												fsumm += $(this).val() + ";";
											}
										});
									}
//									fsumm = ico_t;
//									if(ico_t == '时间' && $("#fsummary_text").val() != ''){
//										fsumm ='<font color="#06DCFC" size="3">(' + $("#fsummary_text").val() + ")</font>";
//									}
								}
								
								$("#addArticle_form").ajaxSubmit({
									url:'addArticle',
									type:'post',
									dataType:'json',
									data:{'culId':column,'fchecked':fchecked,'fsummary':fsumm,'posterJsonStr':$("#posterfresourceurl").val()},
									success:function(data){
										if(data > 0){
											$.growlUI('添加成功！');
											clearFrom();
											kdialog.remove();
										}else{
											$.growlUI('添加失败！');
										}
									},
									error:function(msg){
										$.growlUI('出错');
									}
								});
							}else{
								$.growlUI('请选择栏目！');
							}
						}
					},
					noBtn : {
						name : '取消',
						click : function(e) {
							kdialog.remove();
						}
					}
				});
	_waiting._hide();
};
///清空表单
function clearFrom(){
	$("#ftitle").val('');
	$("#fsearchtext").val('');
	$("#fresourceid").val('');
	$("#ftemplateid").val('');
	$("#ftemplatename").val('');
	$("#videofresourceurl").val('');
	$("#voicefresourceurl").val('');
	contentEditor.html('');
}

//更新保存
function updateSave(types){
//	$.growlUI(contentEditor.html());
	//alert(contentEditor.html());
	if(contentEditor.html() != '')
		$("#_fcontent").val(contentEditor.html());
	
	var fsumm = '';
	if($("#ico_checkbox").attr("checked")){
		var ico_t = $("input[type='checkbox'][name='ico']:checked").size();
		if(ico_t > 0){
			$("input[type='checkbox'][name='ico']:checked").each(function(){
				if($(this).val() == '时间'){
					var date = new Date(),ds;
					if($("#fsummary_text").val() == ''){
						ds = "【" + date.getFullYear() + "-"+ (date.getMonth()+1) + "-" + date.getDate() + "】";
					}else{
						ds = $("#fsummary_text").val();
					}
					fsumm += ds;
				}else{
					fsumm += $(this).val() + ";";
				}
			});
		}
	}
	
	var data={'fchecked':'1','tcolid':$("#tcolid").val(),'updateType':$("#updateType").val() ,'fsummary':fsumm,'posterJsonStr':$("#posterfresourceurl").val()};
	if(types == 2)
		data = {'fchecked':'0','tcolid':$("#tcolid").val(),'updateType':$("#updateType").val(),'fsummary':fsumm,'posterJsonStr':$("#posterfresourceurl").val()};
	$("#updateArticle_form").ajaxSubmit({
		url:'updateArticle',
		type:'post',
		data:data,
		dataType:'json',
		success:function(data){
			if(data > 0){
				$.growlUI('已保存');
				$("#saveTrue").val(1);
			}else{
				$.growlUI('保存失败');
			}
		},
		error:function(msg){
			$.growlUI('保存出错');
		}
	});
}
///移动
function moveTcol(local){
	if($("#saveTrue").val() == 0){
		if(confirm("文章尚未保存，现在保存？")){
			updateSave();
		}
	}else{
		var webid = $("#websiteinfoId").val(),webtitle = $("#websiteinfotitle").val();
		var html = '';
		var divS = '<div id="tcol_dataGrid" style="padding:10px;height:250px;overflow:auto;overflow-x:hidden;">';
		var divE = '</div>';
		
		$.ajax({
			url:'websiteinfoSource',
			type:'post',
			dataType:'json',
			success:function(data){
					html += '选择网站:';
					html += '<select onchange="TcolunmSource(this,\''+local+'\')" style="width:150px;font-size:14px;color:#5E5E5E" ><option value="" disabled="disabled" selected="selected">----站点列表----</option>';
				$.each(data,function(i,u){
					if(webid != '' && webid != null){
						if(u.id == webid){
							html += '<option value="'+u.id+'" selected="selected">'+u.ftitle+'</option>';
						}else{
							html += '<option value="'+u.id+'">'+u.ftitle+'</option>';
						}
					}else{
						html += '<option value="'+u.id+'">'+u.ftitle+'</option>';
					}
				});
				html += '</select>';
			
				var oldTcolid = $("#tcolid").val();
				
				if(webid != '' && webid != null){
					$.ajax({
						url:'tcolunmSource',
						type:'post',
						data:{'webid':webid},
						dataType:'json',
						success:function(data){
							html += divS;
							html +=	$.fn.simpleTree(data,local,true,webtitle);
							html += divE;
							moveClick(html,oldTcolid);
						},
						error:function(msg){
							$.growlUI('栏目加载出错');
						}
					});
						
				}else{
					html += divS + divE;
					moveClick(html,oldTcolid);
				}	
			},
			error:function(msg){
				$.growlUI('网站数据加载出错');
			}
		});
	}
}
function moveClick(html,oldTcolid){
	//模板
	$.ajax({
		url:'templateEntitySource',
		type:'post',
		dataType:'json',
		success:function(data){
				html += '选择默认模板：<select id="_templateid">';
				html += '<option value="">使用原模板</option>';
			$.each(data,function(i,u){
				html += '<option value="'+u.id+'">'+u.fname+'</option>';
			});
				html += '</select>';
		
	
			var kdialog	= KindEditor.dialog({
				width : 800,
				height: 600,
				title : '栏目',
				body : '<div  style="padding:10px;overflow:auto;overflow-x:hidden;">'+html+'</div>',
				shadowMode:true,
				closeBtn : {
					name : '关闭',
					click : function(e) {
						kdialog.remove();
					}
				},
				yesBtn : {
					name : '确定',
					click : function(e) {
						var ckSize = $("input[type='checkbox'][name='columnId']:checked").size();
						if(ckSize > 0){
							var column = '';
							$("input[type='checkbox'][name='columnId']:checked").each(function(){
								column += ',' + $(this).val();
							});
		//					更新操作
							var articleIdstr = '';
							if($("#articleId").val() == undefined || $("#articleId").val() == ''){
								$("input[type='checkbox'][name='articleId']:checked").each(function(i,u){
									articleIdstr += ',' + $(this).val();
								});
							}else{
								articleIdstr = $("#articleId").val();
							}
		//					alert(articleIdstr);
							
							e.disabled = true;
							
							$.ajax({
								url:'updateArticleWithTcolumn',
								type:'post',
								dataType:'json',
								data:{'tcolunmId':column,'articleId':articleIdstr,'tempId':$("#_templateid").val(),'oldTcolId':oldTcolid},
								success:function(data){
									if(data > 0){
										$.growlUI('操作成功');
										kdialog.remove();
										if($("#allCk") != undefined)
											$("#allCk").attr('checked',false);
										
									}else{
										$.growlUI('操作失败');
									}
								},
								error:function(nmsg){
									$.growlUI('出错');
								}
							});
						}else{
							$.growlUI('请选择栏目！');
						}
					}
				},
				noBtn : {
					name : '取消',
					click : function(e) {
						kdialog.remove();
					}
				}
			});
		},
		error:function(msg){
			$.growlUI('模板加载出错');
		}
	});
}
//更改播放模式
function changePlayType(){
	var html = '播放模式：<select id="play_type">';
	    html += '<option value="">VBR模式</option>';
	    html += '<option value="CBR">CBR模式</option>';
	    html += '</select>';
	
	var kdialog	= KindEditor.dialog({
		width : 350,
		height: 200,
		title : '栏目',
		body : '<div  style="padding:10px;overflow:auto;overflow-x:hidden;text-align:center;">' + html + '</div>',
		shadowMode:true,
		closeBtn : {
			name : '关闭',
			click : function(e) {
				kdialog.remove();
			}
		},
		yesBtn : {
			name : '确定',
			click : function(e) {
				var rid = $("#fresourceid").val();
				if(rid != '' && rid != null){
					$.ajax({
						url:'changePlayType?id=' + rid + '&fdefinition=' + $("#play_type").val(),
						type:'post',
						dataType:'json',
						success:function(data){
							if(data > 0){
								$.growlUI('播放模式已修改');
								kdialog.remove();
							}else{
								$.growlUI('修改失败,请刷新再试');
							}
						},
						error:function(msg){
							$.growlUI('系统错误，请刷新再试');
						}
					});
				}else{
					$.growlUI('未选择视频资源...');
				}
			}
		},
		noBtn : {
			name : '取消',
			click : function(e) {
				kdialog.remove();
			}
		}
	});
}